package com.edu.koTA07.takingOrder;

import java.util.ArrayList;


import com.edu.koTA07.XmlDataSet.CustomerXmlDataSet;
import com.edu.koTA07.adapter.CustomersListAdapter;
import com.edu.koTA07.bean.CustomerBean;
import com.edu.koTA07.sqlHelper.SQLHelper;
import com.edu.koTA07.utils.CustomerUtils;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class JadwalKunjungan extends Activity {	
	private ListView customersList;
    CustomerXmlDataSet customer = null;
    ArrayList<CustomerBean> currentData;
	SQLiteDatabase database;
	SQLHelper helper;
	CustomerBean customerBean;
	CustomersListAdapter customersListAdapter;
	
	CustomerUtils util;
    
	//public ProgressDialog dialog;
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.jadwal_kunjungan);
		util = new CustomerUtils(this);
		init();
    }  
    
    public void init(){
    	customersList = (ListView) findViewById(android.R.id.list);
        currentData = new ArrayList<CustomerBean>();
        currentData = util.loadData();
    	customersListAdapter = new CustomersListAdapter(this, currentData);
		customersList.setAdapter(customersListAdapter);
		customersList.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view,
			        int position, long id) {
				CustomerBean c = customersListAdapter.getItem(position);
				onShowData(c, JadwalKunjungan.this);
				
			}

			

		});	
	}
    
    AlertDialog alert;
    public void onShowData(CustomerBean cust, Context ctx) {
		final CustomerBean thisCust = cust;		
		alert = new AlertDialog.Builder(ctx).setIcon(R.drawable.icon)
	        .setTitle("Display Data")
	        .setMessage(" ------------ Customer -------------\n"
	        		  + "ID: "+thisCust.getIDCustomer()+"\n" 
	        		  + "Nama Toko: "+thisCust.getNamaToko()+"\n"
	        		  + "Nama Pemilik: "+thisCust.getNamaPemilik()+"\n"
	        		  + "Telepon: "+thisCust.getTelepon()+"\n"
	        		  + "Tipe Hari Kunjungan: "+thisCust.getTipeHariKunjungan()+"\n"
	        		  + "Kode Kunjungan: "+thisCust.getKodeKunjungan()+"\n"
	        		  + "Alamat: "+thisCust.getAlamatCustomer()+"\n")
	        .setNegativeButton("Close", new DialogInterface.OnClickListener() {
	            public void onClick(DialogInterface dialog, int whichButton) {
	               alert.cancel();
	            }
	        }).create();			
		alert.show();
	}
	
}   
